package com.base.themvx.adapter

import android.view.ViewGroup
import com.base.themvx.model.MenuItemData
import com.base.themvx.viewholder.MenuItemViewHolder

/**
 ******************(^_^)***********************<br>
 * Author: fee(QQ/WeiXin:1176610771)<br>
 * Date: 2023/8/7<br>
 * Time: 14:35<br>
 * <P>DESC:
 * 菜单适配器
 * </p>
 * ******************(^_^)***********************
 */
class MenuAdapter : AbsSelectableAdapter<MenuItemData, MenuItemViewHolder>() {
    companion object Configs {
        const val PAYLOAD_MENU_HINT_COUNT_CHANGED = "payload_hint_count_changed"
    }

    init {
        curAdapterMode = MODE_SINGLE_CHOICE
    }

    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): MenuItemViewHolder {
        return MenuItemViewHolder(parent)
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * 实现此方法，并使用 helper 完成 item 视图的操作
     *
     * @param holder A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    override fun convert(holder: MenuItemViewHolder?, item: MenuItemData?) {
        holder?.onBindView(item)
    }

    override fun convert(holder: MenuItemViewHolder?, item: MenuItemData?, payloads: List<Any>) {
        holder?.onBindView(item, payloads)
    }

    /**
     * 去判断itemData数据能作为选中依据的唯一标识
     * @param theItemData
     * @return
     */
    override fun toJudgeItemDataUniqueMark(theItemData: MenuItemData?): Any {
        val titleInfo = theItemData?.title ?: ""
        if (titleInfo.isNotBlank()) {
            return titleInfo
        }
        return theItemData?.iconDrawableRes ?: 0
    }

    /**
     * itemView 的双击事件监听者
     */
    var mOnItemMultyClickListener: OnItemMultyClickListener? = null
}